import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

class ScaleTransitionDemo extends StatefulWidget {
  const ScaleTransitionDemo({Key? key}) : super(key: key);

  @override
  _ScaleTransitionDemoState createState() => _ScaleTransitionDemoState();
}

class _ScaleTransitionDemoState extends State<ScaleTransitionDemo> with SingleTickerProviderStateMixin {

  late final  AnimationController _animationController ;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _animationController = AnimationController(vsync: this,duration: Duration(seconds: 1))..addListener((){
      print('animation');
      setState(() {

      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title:Text('scale transition')),
        body:Center(
            child:Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                        width:100,
                        height:100,
                        color:Colors.blue
                    ),
                    ScaleTransition(scale: _animationController,child: Container(
                        width:100,
                        height:100,
                        color:Colors.blue
                    ),),
                    Transform.scale(scale: _animationController.value,child:  Container(
                        width:100,
                        height:100,
                        color:Colors.blue
                    ),),
                  ],
                ),

                ElevatedButton(onPressed: (){
                  _animationController.forward();

                }, child: Text('forward')),
                ElevatedButton(onPressed: (){
                  _animationController.value += 0.5;
                  print(_animationController.value);

                }, child: Text('+')),
                ElevatedButton(onPressed: (){
                  _animationController.animateTo(1,duration: Duration(seconds: 2));
                }, child: Text('manual forward')),
                ElevatedButton(onPressed: (){
                  _animationController.animateTo(0,duration: Duration(seconds: 2));
                }, child: Text('back'))
              ],
            )
        )
    );
  }
}
